import React, { useRef } from 'react';
import MyContext from '../context/MyContext';
const InputView = ({ addMsg }) => {
  let msgRefInput = useRef('msg')
  const sendMsg = () => {
    console.log(msgRefInput.current.value);
    addMsg(msgRefInput.current.value)
  }
  return (


    <MyContext.Consumer>
      {
        ({ addMsg }) => {
          return (
            <div>
              <input ref={msgRefInput} type="text" className='inputStyle' />
              <button type="button" onClick={sendMsg}>发送</button>
            </div>
          )
        }
      }
    </MyContext.Consumer>

  );
}

export default InputView;

